#include "FI_ShiborData.h"
#include <msgcenter/FIMsgProcess.h>
#include <qbkernel/include/qb_base.h>
#include <qbprotocol/include/rdProto.h>
#include <qbprotocol/include/SSFIModel.h>
#include <qbtools/message/MessagePoster.h>

FIShiborData::FIShiborData()
{
	m_vctOrder = { "O/N", "3M",	"1W", "2W", "1M", "6M", "9M","1Y" };
	clear();
}

void FIShiborData::clear()
{
	m_dataList.m_List.clear();
}

const std::vector<std::string>& FIShiborData::getOrder()
{
	return m_vctOrder;
}

const xShiborList_c& FIShiborData::getData()
{
	return m_dataList;
}

void FIShiborData::reqData(MessageReceiver* msgRecv)
{
	static bool reqOnce = false;
	if (reqOnce)return;
	reqOnce = true;

	qb::SSRequestMsg msg;
	msg.m_pRequest = nullptr;
	msg.m_FuncID = E_FID_QB_SHIBOR_QUERY;
	MessagePoster poster(&msg, qbmsg::fixedincome::EncodeFunc);
	poster.send(msgRecv);

	PushMsgInfo pmi3(E_FID_QB_SHIBOR_PUSH, "", nullptr);
	msg.m_FuncID = E_FID_QB_SHIBOR_PUSH;
	msgRecv->registPush(pmi3, &msg, qbmsg::fixedincome::EncodeFunc);
}

bool FIShiborData::onReceive(int32_t funcId, const qb::SSAckMsg& msg)
{
	if (funcId != E_FID_QB_SHIBOR_QUERY && funcId != E_FID_QB_SHIBOR_PUSH)return false;

	SCOPED_MUTEX(m_lock);
	clear();
	xShiborList_c* pdata = (xShiborList_c*)msg.m_pRet;
	if (!pdata)return false;

	m_dataList.m_List = pdata->m_List;
	return true;
}
